package com.sf.wc.wordfilter;

import java.util.HashMap;
import java.util.Map;

import com.sf.wc.constant.Constant;

/**
 * 描述：统计给定中文数字
 * 
 * <pre>HISTORY
 * ****************************************************************************
 *  ID   DATE           PERSON          REASON
 *  1    2017年12月5日      Simba.Hua         Create
 * ****************************************************************************
 * </pre>
 * @author Simba.Hua
 */
public class ChineseWordFilter implements WordFilter{
	
	private Map<Character,Integer> counter;
	
	public ChineseWordFilter() {
		 counter = new HashMap<>();
	}

	@Override
	public void doFilter(final String word) {
		String text = word;
		for(int i = 0; i < text.length(); i++){
			char ch = text.charAt(i);
			if(ch < Constant.CHINESE_BEGIN_CHAR || ch > Constant.CHINESE_END_CHAR) {
				continue;
			}
			if(counter.containsKey(ch)) {
				counter.computeIfPresent(ch, (key,value) ->  (value+1));
			} else {
				counter.put(ch, 1);
			}
		}
	}
	
	@Override
	public Map<Character, Integer> getCounter() {
		return counter;
	}

}
